package com.jwthhealth_pub.community.view;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.Button;

import com.jwthhealth_pub.R;
import com.jwthhealth_pub.common.base.BaseActivity;
import com.jwthhealth_pub.common.view.TitleLayout;
import com.jwthhealth_pub.community.view.adapter.CommunityApplyAdapter;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 报告授权页面
 * Created by liuzhen on 2017/12/18.
 */

public class CommunityApplyActivity extends BaseActivity {
    @BindView(R.id.title_layout)
    TitleLayout titleLayout;
    @BindView(R.id.rv_apply_reports)
    RecyclerView rvApplyReports;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_community_apply);
        ButterKnife.bind(this);

        getThraReprots();
    }

    private void getThraReprots() {
        ArrayList<Object> data = new ArrayList<>();

        for (int i = 0; i < 4; i++) {
            data.add(new Object());
        }

        rvApplyReports.setLayoutManager(new LinearLayoutManager(this));
        rvApplyReports.setAdapter(new CommunityApplyAdapter(this, data));
    }

    @Override
    protected void title() {
        titleLayout.setOnTitleLayoutListener(new TitleLayout.TitleLayoutListener() {
            @Override
            public void leftclick() {
                finish();
            }

            @Override
            public void leftTextClick() {

            }

            @Override
            public void rightclick() {

            }

            @Override
            public void rightTextClick() {

            }
        });
    }

    public void showApplyDialog(int type) {
        final android.app.AlertDialog.Builder builder = new android.app.AlertDialog.Builder(this);
        final android.app.AlertDialog alertDialog = builder.create();

        if (type == 0) {
            View applyView = View.inflate(this, R.layout.item_community_apply_dialog, null);
            View confirmBtn = applyView.findViewById(R.id.btn_community_appley_confirm);
            View cancelBtn = applyView.findViewById(R.id.btn_community_appley_cancel);

            confirmBtn.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    alertDialog.dismiss();
                    showApplyDialog(1);
                }
            });

            cancelBtn.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    alertDialog.dismiss();
                }
            });
            alertDialog.setView(applyView);
        } else if (type == 1) {
            View checkView = View.inflate(this, R.layout.item_community_check_dialog, null);
            Button confimBtn = checkView.findViewById(R.id.btn_community_appley_confirm_confirm);
            confimBtn.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    alertDialog.dismiss();
                }
            });
            alertDialog.setView(checkView);
        }
        //build show 的时候会有单独的阴影?
        alertDialog.show();
    }

    public void gotoUnscramble() {
        startActivity(new Intent(this, CommunityUnscrambleActivity.class));
    }
}
